package models

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

//保存全局的连接
var ormSingleton orm.Ormer

func GetOrm() (o1 orm.Ormer) {
	if ormSingleton == nil {
		ormSingleton = orm.NewOrm()
		ormSingleton.Using("default")
	} else {

	}
	return ormSingleton
}

func ModelsRegisterModel() {
	maxIdle := 30
	maxConn := 30
	orm.Debug = true
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("mysql::url"))
	orm.SetMaxIdleConns("default", maxIdle)
	orm.SetMaxOpenConns("default", maxConn)
	orm.RegisterModel(
		new(Menu),
		new(Tables),
		new(User),
	)
}
